package com.jjb.common.view;

import cn.hutool.http.HttpUtil;
import com.jjb.common.view.draw.GrawCanvas;
import com.jjb.common.view.draw.TableGrawCanvas;
import com.jjb.common.view.model.Table;
import com.jjb.common.view.model.TableRow;

import java.awt.*;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class TestMain {

    public static void main(String[] args) throws Exception{
        Font tableFont = new Font("微软雅黑", Font.PLAIN, 40);
        List<Map<String,String>> tableContent = new ArrayList<>();
        Map tableMap = new HashMap();
        tableMap.put("key1","某某某安全员培训课程某某某安全员培训课程某某某安全员培训课程某某某安全员培训课程某某某安全员培训课程某某某安全员培训课程某某某安全员培训课程");
        tableMap.put("key2","key2");
        tableMap.put("key3","key3");
        tableContent.add(tableMap);

        tableMap = new HashMap();
        tableMap.put("key1","123");
        tableMap.put("key2","key2");
        tableMap.put("key3","key3");
        tableContent.add(tableMap);

        tableMap = new HashMap();
        tableMap.put("key1","123");
        tableMap.put("key2","key2");
        tableMap.put("key3","key3");
        tableContent.add(tableMap);

        tableMap = new HashMap();
        tableMap.put("key1","123");
        tableMap.put("key2","key2");
        tableMap.put("key3","key3");
        tableContent.add(tableMap);


        List<TableRow> tableRows = new ArrayList<>();
        TableRow tableRow1 = new TableRow();
        tableRow1.setHeadName("课程名称课程名称课程名称课程名称课程名称");
        tableRow1.setProperty("key1");
        tableRow1.setWidth(300);
        tableRow1.setHeight(100);
        tableRow1.setTextAlign(1);
        tableRow1.setBackGroundColor(new Color(242,248,255));
        tableRows.add(tableRow1);
        TableRow tableRow2 = new TableRow();
        tableRow2.setHeadName("学时");
        tableRow2.setProperty("key2");
        tableRow2.setWidth(200);
        tableRows.add(tableRow2);
        TableRow tableRow3 = new TableRow();
        tableRow3.setHeadName("操作");
        tableRow3.setProperty("key3");
        tableRow3.setWidth(200);
        tableRows.add(tableRow3);

        Table table = new Table();
        table.setMinLineHeight(100);
        table.setTableRows(tableRows);

        TableGrawCanvas tableGrawCanvas = new TableGrawCanvas(160,150, table, tableContent);
        tableGrawCanvas.setFont(tableFont);
        tableGrawCanvas.setHeader(true);


        List<GrawCanvas> grawCanvas = new ArrayList<>();
        grawCanvas.add(tableGrawCanvas);
        String tempUrl = "https://yn-isp.oss-cn-hangzhou.aliyuncs.com/16921804699401818.jpg";
        File backgroundImage = HttpUtil.downloadFileFromUrl(tempUrl,"C:\\Users\\Administrator\\Downloads\\16916594310144902.jpg");

        ImageUtil.imageDrawCancas("C:\\Users\\Administrator\\Downloads\\16916594310144902.jpg", "C:\\Users\\Administrator\\Downloads\\1.jpg", grawCanvas);
    }

}
